package com.henme.crm.util.mybatis;

import com.henme.crm.util.page.Page;


public class DB2Dialect implements Dialect {

    @Override
    public String getLimitString(Page page, String sql) {
        //这个offset 要考虑是否+1
        int offset = (page.getPageNo() - 1) * page.getPageSize()+1;
        StringBuffer pagingSelect = new StringBuffer(sql);
        pagingSelect .append("SELECT * FROM (SELECT PAGE_B.*, ROWNUMBER() OVER() AS RN FROM ( ");
        pagingSelect.append(sql);
        pagingSelect.append(" ) AS PAGE_B )AS PAGE_A WHERE PAGE_A.RN BETWEEN ").append(offset).append(" AND ").append(offset + page.getPageSize() - 1);
        return pagingSelect.toString();
    }
}
